<?php
    class Home_content_m extends Model{
        function Home_content_m(){
            parent::Model();
            $this->load->database();
            $this->load->library('pagination');
        }
        function get_all_contents($per_page,$off_set){
            $this->db->select();
            $this->db->from('content');
            $this->db->where('is_paid', 1);
             $this->db->order_by('id_content','DESC');
            $this->db->limit($per_page,$off_set);
           
            $query = $this->db->get();
            return $query->result_array();    
        }
        function delete_content($id){
            return $this->db->delete('content',array('id_content'=>$id));
        }
        function post_content($data){
            return $this->db->insert('content',$data);
        }
        function get_content_by_id($id){
            $query = $this->db->get_where('content',array('id_content'=>$id));
            return $query;
        }
        function update_content($data,$id){
            return $this->db->update('content',$data,array('id_content'=>$id));
        }
        function count_paid_contents(){
            $this->db->select('is_paid');
            $this->db->from('content');
            $this->db->where(array('is_paid'=>1));
            $query = $this->db->get();
            return count($query->result_array());
        }
        function count_content_search($firstname,$name,$year_die){
            $this->db->select();
            $this->db->from('content');
            if($firstname!='_'){
                $this->db->like('name',$firstname); 
            }
            if($name!='_'){
                $this->db->or_like('prename', $name); 
            }
            if($year_die!='_'){
                $this->db->or_like('death', $year_die); 
            }
            $query = $this->db->get();
            return count($query->result_array()); 
        }
        function search_contents($firstname,$name,$year_die,$per_page,$off_set){
            $this->db->select();
            $this->db->from('content');
            if($firstname!='_'){
                $this->db->like('name',$firstname); 
            }
            if($name!='_'){
                $this->db->or_like('prename', $name); 
            }
            if($year_die!='_'){
                $this->db->or_like('death', $year_die); 
            }
            $this->db->limit($per_page,$off_set);              
            $query = $this->db->get();
            return $query->result_array();
        }
        
         function add_comment($data){
            $query = $this->db->insert('comment_content',$data);
            return $query;                
        }
        function list_comment(){
            $this->db->select();
            $this->db->from('comment_content');
            $this->db->where('is_accepted', 1);
            $this->db->order_by('id','ASC');
            $query = $this->db->get();
            return $query->result_array();    
        }
    }
?>
